<template>
	<div class="content">
		<div class="clear">
			<Form :model="query" label-position="left" :label-width="100">
				<Input v-model="query.id" class="w200 m-r10" placeholder="个人ID" />
				<Input v-model="query.userName" class="w200 m-r10" placeholder="用户名" />
				<Input v-model="query.tradeId" class="w200 m-r10" placeholder="交易编号 " />
				<DatePicker type="daterange" split-panels placeholder="请选择时间段" class="w200 m-r10" format="yyyy-MM-dd" @on-change="getTime">
				</DatePicker>
				<Button type="primary" v-on:click="getConditionQuery">查询</Button>
			</Form>
		</div>
		<fieldset>
			<legend>汇总</legend>
			<div>
				<table>
					<tbody>
						<tr>
							<td v-for="(item,index) in walletInfo" :key="index"><span v-text="'累计转入' + item.name + '：'"></span>
								<span class="blue" v-text="Fixed(item.sum,8)">0</span>
							</td>
							<!-- <td>
								累计转入ESTATE:
								<span class="blue">{{ }}</span>
							</td>
							<td>
								累计转入USDT:
								<span class="blue">{{ }}</span>
							</td> -->
						</tr>
					</tbody>
				</table>
			</div>
		</fieldset>
		<Button class="daochu" type="primary" size="large" @click="exportData" :loading="dcShow">
            <Icon type="ios-download-outline"></Icon>导出
		</Button>
		<Table stripe :columns="columns" :data="conditionQuery" ref="table" :loading="loading"></Table>
		<Page :total="info" show-elevator :page-size="pageSize" show-total @on-change="cuctGetQuery" :current.sync="page"></Page>
	</div>
</template>
<script>
export default {
  data () {
    return {
      dcShow: false,
      loading: false,
      walletInfo: null, // 总钱包信息
      moneySummary: '', // 提币汇总
      dataValue: ['', ''], // 时间段值
      query: {
        id: '',
        tradeId: '',
        userName: ''
      },
      conditionQuery: [], // 条件查询的结果
      info: null, // 总条数
      page: 1, // 页数
      pageSize: 20, // 每页多少条
      current: 1,
      modelIndex: '', // 审核成功时候需要用到的 ID
      value: '', // 审核失败的时候填入的值
      downList: [],
      jsonData: [],
      detailList: [],
      columns: [{
        title: '个人ID',
        key: 'uuid',
        align: 'center',
        render: (h, params) => {
          return h('div', params.row.uuid == null ? '#' : params.row.uuid)
        }
      },
      {
        title: '用户名',
        key: 'userName',
        align: 'center',
        render: (h, params) => {
          return h('div', params.row.userName == null ? '#' : params.row.userName)
        }
      },
      {
        title: '到账数量',
        key: 'num',
        align: 'center',
        render: (h, params) => {
          return h('div', params.row.num == null ? '#' : this.Fixed(params.row.num, 4))
        }
      },
      {
        title: '币种名称',
        key: 'coinId',
        align: 'center',
        render: (h, params) => {
          return h('div', params.row.coinId == null ? '#' : this.coinIdFormat(params.row.coinId))
        }
      },
      {
        title: '交易编号',
        key: 'txId',
        align: 'center',
        render: (h, params) => {
          return h('div', params.row.txId == null ? '#' : params.row.txId)
        }
      },
      {
        title: '创建时间',
        key: 'createTime',
        align: 'center',
        sortable: true,
        render: (h, params) => {
          return h('div', params.row.createTime == null ? '#' : params.row.createTime)
        }
      }
      ]
    }
  },
  mounted () {
    this.$Message.config({ // 配置弹窗的位置
      top: 250
    })
    this.getQuery() // 提现审核列表查询
  },
  methods: {
    getQuery () { // 提现审核列表查询
      let params = this.qs.stringify({
        pn: this.page, // 当前页【可选，默认1】
        size: this.pageSize, // 每页记录数【可选，默认20】
        userName: this.query.userName, // 转账编号
        uuid: this.query.id, // 用户 uuid
        txid: this.query.tradeId, // 1.转赠 2.待审核 3.转账中 4.成功 5.审核不通过
        startTime: this.dataValue[0] == '' ? '' : this.dataValue[0] + ' 00:00:00',
        endTime: this.dataValue[1] == '' ? '' : this.dataValue[1] + ' 23:59:59'
      })
    
      this.axios.post('/admin/accounting/withdraw/into', params).then(res => {
        if (res.data.code == 200) {
          console.log(res);
          this.conditionQuery = res.data.data.itemList.records
          //						this.walletInfo = res.data.data.sum
          this.info = res.data.data.itemList.total
          this.loading = false
        }
      })
      this.axios.get('/admin/accounting/withdraw/into/sum').then(res => {
        if (res.data.code == 200) {
          this.walletInfo = res.data.data
        }
      })
    },
    cuctGetQuery (page) { // 提现审核列表分页查询
      let spy
      if (this.query.state == 0) {
        spy = ''
      } else {
        spy = this.query.state
      }
      this.loading = true
      let params = this.qs.stringify({
        pn: page, // 当前页【可选，默认1】
        size: this.pageSize, // 每页记录数【可选，默认20】
        userName: this.query.userName, // 转账编号
        uuid: this.query.id, // 用户 uuid
        txid: this.query.tradeId, // 1.转赠 2.待审核 3.转账中 4.成功 5.审核不通过
        startTime: this.dataValue[0] == '' ? '' : this.dataValue[0] + ' 00:00:00',
        endTime: this.dataValue[1] == '' ? '' : this.dataValue[1] + ' 23:59:59'
      })
      this.axios.post('/admin/accounting/withdraw/into', params).then(res => {
        if (res.data.code == 200) {
          this.conditionQuery = res.data.data.itemList.records
          this.info = res.data.data.itemList.total
          this.loading = false
        }
      })
    },
    getConditionQuery () { // 提现审核列表条件查询
      this.loading = true
      this.page = 1
      let params = this.qs.stringify({
        pn: this.page, // 当前页【可选，默认1】
        size: this.pageSize, // 每页记录数【可选，默认20】
        userName: this.query.userName, // 转账编号
        uuid: this.query.id, // 用户 uuid
        txid: this.query.tradeId, // 1.转赠 2.待审核 3.转账中 4.成功 5.审核不通过
        startTime: this.dataValue[0] == '' ? '' : this.dataValue[0] + ' 00:00:00',
        endTime: this.dataValue[1] == '' ? '' : this.dataValue[1] + ' 23:59:59'
      })
        // console.log(params);
      this.axios.post('/admin/accounting/withdraw/into', params).then(res => {
        if (res.data.code == 200) {
          this.conditionQuery = res.data.data.itemList.records
          this.info = res.data.data.itemList.total
          this.loading = false
        }
      })
    },
    exportData () { // 导出
      this.jsonData = []
      this.dcShow = true
      this.axios.post('/admin/accounting/withdraw/into', this.qs.stringify({
        pn: this.page, // 当前页【可选，默认1】
        size: this.pageSize, // 每页记录数【可选，默认20】
        userName: this.query.userName, // 转账编号
        uuid: this.query.id, // 用户 uuid
        txid: this.query.tradeId, // 1.转赠 2.待审核 3.转账中 4.成功 5.审核不通过
        startTime: this.dataValue[0] == '' ? '' : this.dataValue[0] + ' 00:00:00',
        endTime: this.dataValue[1] == '' ? '' : this.dataValue[1] + ' 23:59:59'
      })).then(res => {
        if (res.data.code == 200) {
          this.axios.post('/admin/accounting/withdraw/into', this.qs.stringify({
            pn: 1, // 当前页【可选，默认1】
            size: res.data.data.itemList.total, // 每页记录数【可选，默认20】
            userName: this.query.userName, // 转账编号
            uuid: this.query.id, // 用户 uuid
            txid: this.query.tradeId, // 1.转赠 2.待审核 3.转账中 4.成功 5.审核不通过
            startTime: this.dataValue[0] == '' ? '' : this.dataValue[0] + ' 00:00:00',
            endTime: this.dataValue[1] == '' ? '' : this.dataValue[1] + ' 23:59:59'
          })).then(res => {
            if (res.data.code == 200) {
              this.downList = res.data.data.itemList.records
              this.downList.forEach((row, index) => {
                this.jsonData.push({
                  uuid: this.downList[index].uuid,
                  userName: this.downList[index].userName,
                  num: this.Fixed(this.downList[index].num),
                  coinId: this.coinIdFormat(this.downList[index].coinId),
                  txId: this.downList[index].txId,
                  createTime: this.stringToTime(this.downList[index].createTime)
                })
              })
              let str = `个人ID,用户名,到账数量,币种类型,交易编号,创建时间\n`
              this.downLoad(this.jsonData, str, '转入列表')
            }
          })
        }
      })
    },
    getTime (daterange) { // 处理时间段时间格式
      this.dataValue = daterange
    }
  }
}
</script>
